package com.sharewin.bean;

import com.sharewin.constant.ServerResponseEnum;
import lombok.Data;

/**
 * @author chenghai
 * @date 2021年07月17日 14:17
 */
@Data
public class ResponseVO<T> {

    private static final long serialVersionUID = -1005863670741860901L;
    // 响应码
    private Integer code;

    // 描述信息
    private String message;

    // 响应内容
    private T data;

    private ResponseVO(ServerResponseEnum responseCode) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
    }

    private ResponseVO(ServerResponseEnum responseCode, T data) {
        this.code = responseCode.getCode();
        this.message = responseCode.getMessage();
        this.data = data;
    }

    private ResponseVO(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 返回成功信息
     *
     * @param data 信息内容
     * @param <T>
     * @return
     */
    public static <T> ResponseVO success(T data) {
        return new ResponseVO<>(ServerResponseEnum.SUCCESS, data);
    }

    /**
     * 返回成功信息
     *
     * @return
     */
    public static ResponseVO success() {
        return new ResponseVO(ServerResponseEnum.SUCCESS);
    }

    /**
     * 返回错误信息
     *
     * @param responseCode 响应码
     * @return
     */
    public static ResponseVO error(ServerResponseEnum responseCode) {
        return new ResponseVO(responseCode);
    }
}
